<?php
/**
 * Created by PhpStorm.
 * User: 20860
 * Date: 2024/1/5
 * Time: 13:44
 */
namespace app\port\controller;

use app\port\model\News;
use think\Request;

class Newss extends Base{
    /**
     * 获取10条最新的数据
     */
    public function getTopNews(){
        $res = News::where(["status"=>1])->order(["id"=>"asc"])->field("id,title,cover,create_time")->select();
        if($res){
<<<<<<< HEAD
            return $this->repuest_json($res,true);
        }else{
            return $this->repuest_json($res);
=======
            return $this->request_json($res,true);
        }else{
            return $this->request_json($res);
>>>>>>> shool
        }
    }
    /**
     * 获取当前详细新闻
     */
    public function getNewsDetail(Request $request){
        $id = $request->post("newsid") ? $request->post("newsid") : 0;
        $res = News::get($id);
        if($res){
<<<<<<< HEAD
            return $this->repuest_json($res,true);
        }else{
            return $this->repuest_json($res);
        }
    }
    /**
     *
=======
            return $this->request_json($res,true);
        }else{
            return $this->request_json($res);
        }
    }
    /**
     *获取分页的新闻列表
>>>>>>> shool
     */
    public function getAllNews(Request $request){
        $page = $request->post("pageNumber")-1;
        $length = $request->post("length");
        $res = News::limit($page * $length,$length)->select();
<<<<<<< HEAD
        if($res){
            return $this->repuest_json($res,true);
        }else{
            return $this->repuest_json($res);
=======
        $total = ceil(News::coun("id") / $length);
        if($res){
           return $this->request_json_total($res,$total,true);
        }else{
            return $this->request_json($res);
>>>>>>> shool
        }

    }
}